'use strict'

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    const { STRING, TEXT, INTEGER, DATE, BOOLEAN } = Sequelize
    await queryInterface.createTable('article', {
      id: {
        type: INTEGER(20).UNSIGNED,
        primaryKey: true,
        autoIncrement: true,
        comment: '主键id'
      },
      detail_id: {
        type: INTEGER(20).UNSIGNED,
        allowNull: false,
        comment: '文章id',
        references: {
          model: 'article_detail',
          key: 'id'
        },
        onDelete: 'CASCADE'
      },
      titile: {
        type: STRING(100),
        allowNull: false,
        comment: '标题'
      },
      desc: {
        type: TEXT,
        allowNull: false,
        comment: '描述'
      },
      poster: {
        type: STRING(200),
        allowNull: false,
        comment: '封面图'
      },
      likes: {
        type: INTEGER(11),
        allowNull: false,
        defaultValue: 0,
        comment: '点赞人数'
      },
      views: {
        type: INTEGER(11),
        allowNull: false,
        defaultValue: 0,
        comment: '浏览人数'
      },
      status: {
        type: BOOLEAN,
        allowNull: false,
        defaultValue: 1,
        comment: '状态 0:禁用 1:启用'
      },
      created_at: DATE,
      updated_at: DATE
    })
  },

  async down(queryInterface) {
    queryInterface.dropTable('articles')
  }
}
